package com.wrx.club_management_backend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wrx.club_management_backend.entity.News;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

@Mapper
public interface NewsMapper extends BaseMapper<News> {
    /**
     * 根据俱乐部ID查询管理员用户ID
     * 修复IN子句为空的问题
     */
    @Select("<script>select DISTINCT user_id from tb_club_manager " +
            "<where>" +
            "<if test=\"clubIds != null and clubIds.size() > 0\">" +
            "club_id in " +
            "<foreach collection=\"clubIds\" item=\"id\" open=\"(\" separator=\",\" close=\")\">" +
            "#{id}" +
            "</foreach>" +
            "</if>" +
            "<if test=\"clubIds == null or clubIds.size() == 0\">" +
            "1 = 0" + // 当clubIds为空时返回空结果集
            "</if>" +
            "</where>" +
            "</script>")
    List<Long> selectManagerByCLubId(@Param("clubIds") Set<String> clubIds);
}
